package com.chen10.cattle.controller;

import com.chen10.cattle.common.enums.response.SuccessMsgEnum;
import com.chen10.cattle.common.exception.BusinessException;
import com.chen10.cattle.common.protocal.ResponseResult;
import com.chen10.cattle.common.protocal.ResponseVO;
import com.chen10.cattle.model.vo.SendEmailVO;
import com.chen10.cattle.service.EmailCodeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/email")
@Validated
public class EmailCodeController {

    @Resource
    private EmailCodeService emailCodeService ;

    /**
     * 发送邮箱验证码
     * @param sendEmailVO
     * @return
     */
    @PostMapping("/send")
    public ResponseVO sendCode(@RequestBody SendEmailVO sendEmailVO)
    {
        try{
            emailCodeService.sendCode(sendEmailVO);
        }catch (BusinessException e){
            return ResponseResult.error(e.getCode(),e.getMessage());
        }
        return ResponseResult.success(SuccessMsgEnum.EMAILCODE_SEND_SUCCESS);
    }
}
